package com.company.回溯;

import java.util.ArrayList;
import java.util.List;

public class Leet77 {
    private static int n,k;
    private void dfs(List<List<Integer>> ans,List<Integer> path,int i){
        if(n-i+path.size()<k)
            return;
        if(path.size()==k){
            ans.add(new ArrayList<>(path));
            return;
        }
        //不选
        dfs(ans,path,i+1);
        //选
        path.add(i+1);
        dfs(ans,path,i+1);
        //回溯
        path.remove(path.size()-1);
    }
    public List<List<Integer>> combine(int n, int k) {
        this.n = n;
        this.k = k;
        List<List<Integer>> ans=new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        dfs(ans,path,0);
        return ans;
    }
}
